package top.ffhome.concurrent.beautiful.ch01;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallerTest {
    private static final Log log = LogFactory.get();

    public static class CallerTask implements Callable<String> {
        @Override
        public String call() throws Exception {
            log.info("caller task start: {}", Thread.currentThread());
            return "hello";
        }
    }

    public static void main(String[] args) throws InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new CallerTask());
        new Thread(futureTask).start();
        try {
            // 等待任务执行完成，获取结果
            String result = futureTask.get();
            log.info(result);
        } catch (ExecutionException e) {
            log.error(e);
        }
    }
}
